package com.example.text6_client;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.widget.EditText;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import butterknife.Unbinder;

public class MainActivity extends AppCompatActivity {
    @BindView(R.id.et_main_content)
    EditText et_main_content;

    private ClientThread clientThread;
    private Unbinder unbinder;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setContentView(R.layout.activity_main);

        unbinder = ButterKnife.bind(MainActivity.this);

        clientThread = new ClientThread();
        clientThread.start();
    }

    @Override
    protected void onDestroy() {
        if (clientThread != null) {
            clientThread.onDestroy();
        }
        if (unbinder != null) {
            unbinder.unbind();
        }
        super.onDestroy();
    }

    @OnClick({R.id.btn_main_send})
    void OnClick() {
        String str = et_main_content.getText().toString();
        if (clientThread != null) {
            clientThread.send(str);
        }
    }
}